<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  <title>OpenLayers - 基本概念</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/components/prism-core.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/plugins/autoloader/prism-autoloader.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/plugins/toolbar/prism-toolbar.min.js"></script>
  <script
    src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js"></script>
  <link rel="stylesheet" type="text/css"
    href="https://fonts.googleapis.com/css?family=Quattrocento+Sans:400,400italic,700" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css"
    crossorigin="anonymous">
  <link rel="stylesheet" type="text/css"
    href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.2/css/fontawesome.min.css"
    crossorigin="anonymous">
  <link rel="stylesheet" type="text/css"
    href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.2/css/solid.css" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css"
    href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.2/css/brands.css" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="/theme/ol.css">
  <link rel="stylesheet" type="text/css" href="/theme/site.css">
  <link rel="icon" type="image/svg+xml" href="/theme/img/logo-light.svg" media="(prefers-color-scheme: light)" />
  <link rel="icon" type="image/svg+xml" href="/theme/img/logo-dark.svg" media="(prefers-color-scheme: dark)" />
</head>

<body>
  <header class="navbar navbar-expand-md navbar-dark mb-3 px-3 py-0 fixed-top" role="navigation">
    <a class="navbar-brand" href="/"><img src="/theme/img/logo-dark.svg" width="70" height="70"
        alt="">&nbsp;OpenLayers</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#olmenu"
      aria-controls="olmenu" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <!-- menu items that get hidden below 768px width -->
    <nav class="collapse navbar-collapse" id="olmenu">
      <ul class="nav navbar-nav ms-auto">
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="docdropdown" role="button" data-bs-toggle="dropdown"
            aria-haspopup="true" aria-expanded="false">Docs</a>
          <div class="dropdown-menu dropdown-menu-end mb-3" aria-labelledby="docdropdown">
            <a class="dropdown-item" href="/doc/">Docs</a>
            <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="/doc/quickstart.html"><i class="fa fa-check fa-fw me-2 fa-lg"></i>快速入门</a>
            <a class="dropdown-item" href="/doc/faq.html"><i class="fa fa-question fa-fw me-2 fa-lg"></i>常见问题</a>
            <a class="dropdown-item" href="/doc/tutorials/"><i class="fa fa-book fa-fw me-2 fa-lg"></i>教程</a>

          </div>
        </li>
        <li class="nav-item"><a class="nav-link" href="/en/latest/examples/">Examples</a></li>
        <li class="nav-item dropdown">
          <a class="nav-link dropdown-toggle" href="#" id="apidropdown" role="button" data-bs-toggle="dropdown"
            aria-haspopup="true" aria-expanded="false">
            <i class="fa fa-sitemap me-1"></i>API
          </a>
          <div class="dropdown-menu dropdown-menu-end mb-3" aria-labelledby="apidropdown">
            <a class="dropdown-item" href="/en/latest/apidoc/"><i class="fa fa-sitemap fa-fw me-2 fa-lg"></i>v8.2.0
              (latest)</a </div>
        </li>
      </ul>
    </nav>
  </header>

  <div class="container">
    <h1 id="basic-concepts">基本概念</h1>
    <h2 id="map">Map</h2>
    <p> map (<code>ol/Map</code> 模块)是openlayers的核心组件。 它被渲染到
      <code>目标</code> 容器中 (例如，包含地图的网页上的<code>div</code> 元素)。所有地图属性都可以在构造时配置，或者通过使用setter方法进行配置
      （ 例如：<code>setTarget()</code> ）。

    </p>
    <p>如下示例是在<code>&lt;div&gt;</code>容器中创建一个包含地图。</p>
    <pre><code class="language-xml">&lt;div id=&quot;map&quot; style=&quot;width: 100%; height: 400px&quot;&gt;&lt;/div&gt;
</code></pre>
    <p>下面的脚本使用元素的地图id作为选择器,构建一个渲染在<code>&lt;div&gt;</code>中的 <code>地图</code>。

    </p>
    <pre><code class="language-js">import Map from &#39;ol/Map.js&#39;;

const map = new Map({target: &#39;map&#39;});
</code></pre>
    <h2 id="view">View</h2>
    <p>地图不负责地图的中心、缩放级别和投影等事项。相反，这些都是<code>ol/View</code>实例的属性。</p>
    <pre><code class="language-js">import View from &#39;ol/View.js&#39;;

map.setView(new View({
  center: [0, 0],
  zoom: 2,
}));
</code></pre>
    <p><code>View</code>还具有<code>projection </code>投影属性。 投影决定了地图 <code>center</code>分辨率计算的坐标系和单位。如果没有指定 (如上面的代码片段所示),
      则默认投影为球面墨卡托投影(EPSG:3857), 以米为地图单位。.
    </p>
    <p> <code>zoom</code> 选项是指定地图分辨率的便捷方法。可用的缩放级别由<code>maxZoom</code> (默认值: 28), <code>zoomFactor</code> (默认值: 2) 和
      <code>maxResolution</code> (默认值是通过计算得出的，投影的有效范围适合256x256像素瓦片)确定。从缩放级别 0 开始分辨率为
      <code>maxResolution</code> 每像素单位，
      后续缩放级别的计算方法是将前一个缩放级别的分辨率除以
      <code>zoomFactor</code>,直到达到缩放级别 <code>maxZoom</code> 。
    </p>
    <h2 id="source">Source</h2>
    <p>为了获得一个层的远程数据，OpenLayers使用 <code>ol/source/Source</code> 子类。
      这些可用于免费的商业地图瓦片服务，如OpenStreetMap或Bing，以及OGC源，如WMS或WMTS，以及格式如GeoJSON或KML的矢量数据。</p>
    <pre><code class="language-js">import OSM from &#39;ol/source/OSM.js&#39;;

const source = OSM();
</code></pre>
    <h2 id="layer">Layer</h2>
    <p>图层是源数据的可视化表示形式。OpenLayers有四种基本类型的图层：</p>
    <ul>
      <li><code>ol/layer/Tile</code> - 渲染在网格中提供平铺图像的源，这些网格按特定分辨率的缩放级别进行组织。</li>
      <li><code>ol/layer/Image</code> - 渲染提供任意范围和分辨率的地图图像的源。
      </li>
      <li><code>ol/layer/Vector</code> - 在客户端渲染矢量数据。</li>
      <li><code>ol/layer/VectorTile</code> - 渲染以矢量瓦片形式提供的数据。</li>
    </ul>
    <pre><code class="language-js">import TileLayer from &#39;ol/layer/Tile.js&#39;;

// ...
const layer = new TileLayer({source: source});
map.addLayer(layer);
</code></pre>
    <h2 id="putting-it-all-together">把它们放在一起</h2>
    <p>上面的代码片段可以组合成一个单独的脚本，该脚本渲染一个带有单个瓦片层的地图：</p>
    <pre><code class="language-js">import Map from &#39;ol/Map.js&#39;;
import View from &#39;ol/View.js&#39;;
import OSM from &#39;ol/source/OSM.js&#39;;
import TileLayer from &#39;ol/layer/Tile.js&#39;;

new Map({
  layers: [
    new TileLayer({source: new OSM()}),
  ],
  view: new View({
    center: [0, 0],
    zoom: 2,
  }),
  target: &#39;map&#39;,
});
</code></pre>

  </div>

  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>